<template>
  <div class="table-box" style="height: auto">
    <div class="table-search">
      <el-form :inline="true" :model="form">
        <el-form-item>
          <el-select
            clearable
            v-model="form.merchant_id"
            placeholder="商户"
            filterable
          >
            <el-option
              v-for="item in payMerchantList"
              :key="item.value"
              :label="item.name + '-' + item.merchant_id"
              :value="item.merchant_id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item>
                    <el-input clearable placeholder="商户ID" v-model="form.merchant_id"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-input clearable placeholder="商户名称" v-model="form.merchant_name"></el-input>
                </el-form-item> -->
        <el-form-item>
          <el-date-picker
            clearable
            v-model="form.timeData"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="截止日期"
            :default-time="pickerDefaultTime"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onQuery">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="card content-box">
      <div class="table" style="height: auto">
        <el-table :data="tableData" border v-loading="loading">
          <el-table-column prop="id" label="id" align="center" width="60" />
          <el-table-column
            prop="merchant_id"
            label="商户id"
            align="center"
            width="110"
          />
          <el-table-column
            prop="merchant_name"
            label="商户名称"
            align="center"
            width="150"
          />
          <el-table-column
            prop="account_type"
            label="客户类型"
            align="center"
          />
          <el-table-column label="客户信息" align="left" width="300">
            <template #default="scope">
              <p>公司名称：{{ scope.row.company_name }}</p>
              <p>公司别名：{{ scope.row.company_alias }}</p>
              <p>经营范围：{{ scope.row.company_business }}</p>
              <p>个人姓名：{{ scope.row.real_name }}</p>
              <p>联系方式：{{ scope.row.contact }}</p>
              <p>网站url：{{ scope.row.website }}</p>
              <p>地址信息：{{ scope.row.address }}</p>
            </template>
          </el-table-column>
          <el-table-column
            label="收款人信息"
            align="left"
            width="200"
            style="padding-left: 15px"
          >
            <template #default="scope">
              <p>付款方式：{{ scope.row.pay_way }}</p>
              <p>收款国家：{{ scope.row.receive_country }}</p>
              <p>收款地区：{{ scope.row.receive_city }}</p>
              <p>收款人地址：{{ scope.row.receive_address }}</p>
            </template>
          </el-table-column>
          <el-table-column
            label="银行信息"
            align="left"
            width="300"
            style="padding-left: 5px"
          >
            <template #default="scope">
              <p>银行名称：{{ scope.row.bank_name }}</p>
              <p>银行账号：{{ scope.row.bank_card_number }}</p>
              <p>
                银行国家/城市：{{ scope.row.bank_country }}
                {{ scope.row.bank_city }}
              </p>
              <p>银行地址：{{ scope.row.bank_address }}</p>
              <p>Swift码：{{ scope.row.bank_swift }}</p>
              <p>IBAN码：{{ scope.row.bank_iban }}</p>
              <p>支持币种：{{ scope.row.currency }}</p>
            </template>
          </el-table-column>
          <el-table-column label="附件信息" align="center" width="200">
            <template #default="scope">
              <el-link
                target="_blank"
                style="margin-right: 10px"
                v-if="scope.row.file_data.company_certificate"
                :href="scope.row.file_data.company_certificate"
                :type="
                  scope.row.file_data.company_certificate ? 'success' : 'info'
                "
                >公司注册证书</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.latest_register"
                :href="scope.row.file_data.latest_register"
                :type="scope.row.file_data.latest_register ? 'success' : 'info'"
                >最新商业登记证</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.latest_report"
                :href="scope.row.file_data.latest_report"
                :type="scope.row.file_data.latest_report ? 'success' : 'info'"
                >最新年审报告</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.financial_statements"
                :href="scope.row.file_data.financial_statements"
                :type="
                  scope.row.file_data.financial_statements ? 'success' : 'info'
                "
                >最新财务报表/税表</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.stock_certificate"
                :href="scope.row.file_data.stock_certificate"
                :type="
                  scope.row.file_data.stock_certificate ? 'success' : 'info'
                "
                >所有持股10%以上股东的有效証件</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.invoice"
                :href="scope.row.file_data.invoice"
                :type="scope.row.file_data.invoice ? 'success' : 'info'"
                >INVOICE范本</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.company_organization"
                :href="scope.row.file_data.company_organization"
                :type="
                  scope.row.file_data.company_organization ? 'success' : 'info'
                "
                >公司组织架构</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.company_address"
                :href="scope.row.file_data.company_address"
                :type="scope.row.file_data.company_address ? 'success' : 'info'"
                >公司地址证明(近3个月)</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.bank_statement"
                :href="scope.row.file_data.bank_statement"
                :type="scope.row.file_data.bank_statement ? 'success' : 'info'"
                >银行对账单(近3个月)</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.supplier_agreement"
                :href="scope.row.file_data.supplier_agreement"
                :type="
                  scope.row.file_data.supplier_agreement ? 'success' : 'info'
                "
                >供应商协议及发票(有效期内)</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.sale_agreement"
                :href="scope.row.file_data.sale_agreement"
                :type="scope.row.file_data.sale_agreement ? 'success' : 'info'"
                >销售协议及发票(有效期内)</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.kaihu_zhengjian"
                :href="scope.row.file_data.kaihu_zhengjian"
                :type="scope.row.file_data.kaihu_zhengjian ? 'success' : 'info'"
                >开户授权签字人有效证件+签字印鉴</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.kaihu_zhengjian_addr"
                :href="scope.row.file_data.kaihu_zhengjian_addr"
                :type="
                  scope.row.file_data.kaihu_zhengjian_addr ? 'success' : 'info'
                "
                >开户授权签字人个人地址证明(近3个月)</el-link
              >
              <el-link
                target="_blank"
                style="margin: 0 10px"
                v-if="scope.row.file_data.board_member_address"
                :href="scope.row.file_data.board_member_address"
                :type="
                  scope.row.file_data.board_member_address ? 'success' : 'info'
                "
                >董事地址证明(近3个月)</el-link
              >
            </template>
          </el-table-column>
          <el-table-column
            prop="mer_review_status"
            label="商户审核"
            align="center"
          >
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.mer_review_status == 1
                    ? 'success'
                    : scope.row.mer_review_status == 2
                    ? 'danger'
                    : 'warning'
                "
              >
                {{ scope.row.mer_review_status == 1 ? "已审核" : "未审核" }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="sys_review_status"
            label="系统审核"
            align="center"
          >
            <template #default="scope">
              <el-tag
                :type="
                  scope.row.sys_review_status == 1
                    ? 'success'
                    : scope.row.sys_review_status == 0
                    ? 'warning'
                    : 'danger'
                "
              >
                {{
                  scope.row.sys_review_status == 1
                    ? "已审核"
                    : scope.row.sys_review_status == 2
                    ? "拒绝"
                    : "未审核"
                }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="createtime"
            label="添加时间"
            :formatter="formatterTime"
            align="center"
            width="180"
          ></el-table-column>
        </el-table>
        <div class="table-pagination">
          <el-pagination
            :current-page="pageable.pageNum"
            :page-size="pageable.pageSize"
            :page-sizes="[10, 25, 50, 100]"
            :background="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageable.total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive, computed } from "vue";
import { formatterTime, pickerDefaultTime } from "@/utils/utils";
import { customerListApi } from "@/api/payServerse/payment";
import { GlobalStore } from "@/store";

const globalStore = GlobalStore();
const payMerchantList = computed(() => globalStore.payMerchantList);

const loading = ref(false);
const tableData = ref([]);

const formData = {
  merchant_id: "",
  merchant_name: "",
  timeData: [],
};
const form = reactive({ ...formData });
const pageable = reactive({
  pageNum: 1,
  pageSize: 10,
  total: 0,
});
//参数
const param = () => {
  return {
    page: pageable.pageNum,
    pagesize: pageable.pageSize,
    merchant_id: form.merchant_id,
    merchant_name: form.merchant_name,
  };
};
// 获取表格数据
const getTbaleData = async () => {
  loading.value = true;
  try {
    const res = await customerListApi(param());
    loading.value = false;
    tableData.value = res.data.results;
    pageable.total = res.data.count;
  } catch (error) {
    loading.value = false;
  }
};
//查询
const onQuery = async () => {
  getTbaleData();
};
// 条数
const handleSizeChange = (number) => {
  pageable.pageSize = number;
  getTbaleData();
};
// 页码
const handleCurrentChange = (number) => {
  pageable.pageNum = number;
  getTbaleData();
};
onMounted(() => {
  getTbaleData();
});
</script>
